package com.nopay.dxdwphone.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.nopay.dxdwphone.R;

public class DialogPayResult extends Dialog {

    private Options mOptions;

    public DialogPayResult(@NonNull Activity context, Options options) {
        super(context, R.style.MyDialog);
        if(options == null) options = new Options();
        this.mOptions = options;
    }

    private TextView tv_payResult;
    private TextView tv_payCancel;
    private TextView tv_payConfirm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_pay_result);

        tv_payResult = findViewById(R.id.tv_pay_result);
        tv_payCancel = findViewById(R.id.tv_pay_cancel);
        tv_payConfirm = findViewById(R.id.tv_pay_confirm);

        tv_payResult.setText(mOptions.getResult());
        tv_payConfirm.setText(mOptions.getConfirmText());
        tv_payCancel.setText(mOptions.getCancelText());

        tv_payCancel.setOnClickListener(v -> dismiss());
        tv_payConfirm.setOnClickListener(v -> {
            dismiss();
            if(onPayConfirmListener != null) onPayConfirmListener.onPayConfirm();
        });
    }

    private OnPayConfirmListener onPayConfirmListener;

    public DialogPayResult setOnPayConfirmListener(OnPayConfirmListener onPayConfirmListener) {
        this.onPayConfirmListener = onPayConfirmListener;
        return this;
    }

    public interface OnPayConfirmListener {

        void onPayConfirm();
    }

    public static class Options {

        private String result;

        private String confirmText;

        private String cancelText;

        public String getResult() {
            return result;
        }

        public Options setResult(String result) {
            this.result = result;
            return this;
        }

        public String getConfirmText() {
            return confirmText;
        }

        public Options setConfirmText(String confirmText) {
            this.confirmText = confirmText;
            return this;
        }

        public String getCancelText() {
            return cancelText;
        }

        public Options setCancelText(String cancelText) {
            this.cancelText = cancelText;
            return this;
        }
    }
}
